package dao.Impl;

import com.alibaba.druid.util.JdbcUtils;
import commons.druidJdbcUtil;
import dao.InsertUsers;
import pojo.User;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class addUserDaoImpl implements InsertUsers {
    @Override
    public void addUser(User user) {
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            conn= druidJdbcUtil.getConnection();
            conn.setAutoCommit(false);
            String sql="insert into users values(default,?,?,?,?,?)";
            ps=conn.prepareStatement(sql);
            ps.setString(1,user.getUsername());
            ps.setString(2,user.getUsersex());
            ps.setString(3,user.getUserpwd());
            ps.setString(4,user.getPhoneNum());
            ps.setString(5,user.getQqNum());
            ps.execute();

            conn.commit();

        }catch (Exception e){
            druidJdbcUtil.roolback(conn);
            e.printStackTrace();
        }

    }
}
